package cn.clq.ymcc.controller;

import cn.clq.ymcc.doc.CourseDoc;
import cn.clq.ymcc.dto.CourserSearchDto;
import cn.clq.ymcc.result.JSONResult;
import cn.clq.ymcc.result.PageList;
import cn.clq.ymcc.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 课程Es相关控制层
 */
@RestController
public class CourseEsController {
    @Autowired
    private ICourseEsService courseEsService;

    /**
     * @description: 从ES分页查询课程
     * @param: courseDoc
     * @return: cn.clq.ymcc.result.JSONResult
     * @author clqlongbao
     * @date: 2022/7/27 2:59
     */
    @PostMapping("/course/search")
    public JSONResult search(@RequestBody CourserSearchDto dto){
        return JSONResult.success(courseEsService.search(dto));
    }


//    @PostMapping("/course/search")
//    public PageList<CourseDoc> search(@RequestBody CourserSearchDto dto){
//        return courseEsService.search(dto);
//    }


    /**
     * @description: 保存课程到ES
     * @param: doc
     * @return: cn.clq.ymcc.result.JSONResult
     * @author clqlongbao
     * @date: 2022/7/24 17:38
     */
    @PostMapping("/saveCourse")
    public JSONResult saveCourse(@RequestBody CourseDoc courseDoc){
        courseEsService.saveCourse(courseDoc);
        return JSONResult.success();
    }

    /**
     * @description: 从ES中删除课程
     * @param: courseDoc
     * @return: cn.clq.ymcc.result.JSONResult
     * @author clqlongbao
     * @date: 2022/7/25 17:27
     */
    @PostMapping("/deleteCourse")
    public JSONResult deleteCourse(@RequestBody CourseDoc courseDoc){
        courseEsService.deleteCourse(courseDoc);
        return JSONResult.success();
    }
}
